package main

import (

	"github.com/robfig/cron"
	"github.com/spf13/cobra"
	"os/exec"
	"log"

)

var cronString string

var shellString string

var rootCmd = &cobra.Command{
	Use:   "cron shell run",
	Short: "cron shell run",
	Long: `cron shell run`,
	Run: func(cmd *cobra.Command, args []string) {
	  // Do Stuff Here

	  c := cron.New()  // 新建一个定时任务对象
	      c.AddFunc(cronString, func() {
			err :=exec.Command(shellString).Start()
			if err !=nil {
               log.Println(err)
			}
	      })  // 给对象增加定时任务
	      c.Start()
	      select {
	      }
	},
  }
func main() {
	rootCmd.PersistentFlags().StringVar(&cronString, "cron", "c", "cron string")
    rootCmd.PersistentFlags().StringVar(&shellString, "shell", "s", "shell string")
   
	rootCmd.Execute()
}
